package com.example.oauth2.common.result;

import lombok.Getter;

/**
 * 响应码枚举
 * @author xuwenqian
 */
@Getter
public enum ResultCode {
    /**
     * 响应码枚举
     */
    SUCCESS(1000, "system.success"),
    FAIL(1001, "system.fail"),
    HEADER_INVALID(1002, "system.header.invalid"),
    TOKEN_INVALID(1003, "system.token.invalid"),
    USER_EXISTS(1005, "system.user.already.exists"),
    UNKNOWN(9999, "system.error"),
    ;

    public Integer code;
    public String msg;

    ResultCode(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 根据状态码获取状态码描述
     *
     * @param code 状态码
     * @return String 状态码描述
     */
    public static String getMessage(Integer code) {
        String result = null;
        for (ResultCode r : ResultCode.values()) {
            if (r.code.equals(code)) {
                result = r.msg;
            }
        }
        return result;
    }
}
